package com.atguigu.repservice.controller.front;


import com.atguigu.commonutils.R;
import com.atguigu.repservice.entity.RepSubject;
import com.atguigu.repservice.entity.subject.OneSubject;
import com.atguigu.repservice.service.RepSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author ZhuangLiJiao
 * @since 2021-10-15
 */
@Api(description = "全部行业分类")
@RestController
@RequestMapping("/repservice/subject")
@CrossOrigin
public class RepSubjectController {


    @Autowired
    private RepSubjectService subjectService;


    @ApiOperation("根据id获取名字")
    @GetMapping("getNameById/{id}")
    public String getNameById(@PathVariable("id") String id)
    {
        RepSubject byId = subjectService.getById(id);
        return byId.getTitle();
    }

    //添加行业分类
    //获取上传过来文件，把文件内容读取出来
    @ApiOperation("添加行业分类")
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file) {
        //上传过来excel文件
        subjectService.saveSubject(file, subjectService);
        return R.ok();
    }

    //课程分类列表（树形）
    @ApiOperation("获取全部商业分类（生成商业分类树）")
    @GetMapping("getAllSubject")
    public R getAllSubject() {
        //list集合泛型是一级分类
        List<OneSubject> list = subjectService.getAllOneTwoSubject();
        return R.ok().data("list", list);
    }

}

